package 设计模式;

public class Singleton {
    // 静态私有成员变量，保证实例唯一性
    private static Singleton instance = null;
    // 私有构造函数，保证实例由类自行创建
    private Singleton(){}
    // 静态共有工厂方法，向系统提供唯一实例
    public static Singleton getInstance(){
        if(instance == null){
            instance = new Singleton();
        }
        return instance;
    }
    public static void main(String[] args) {
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();
        System.out.println(s1 == s2);
    }
}
